
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
      roles: ['admin'],
      introduction: 'I am a super administrator',
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      name: 'Super Admin',
      asyncRouterMap:[
        {
          path: '/example',
          component: 'Layout',
          redirect: '/example/table',
          name: 'example',
          parentId: '',
          id:'example1',
          meta: { title: '例子', icon: 'example' },
        },
        {
          path: 'table',
          name: 'Table',
          parentId: 'example1',
          id:'table',
          component: () => import('@/views/table/index'),
          meta: { title: '表格', icon: 'table' }
        },
        {
          path: 'complex-table',
          name: 'complex-table',
          parentId: 'example1',
          id:'complex-table',
          component: () => import('@/views/table/complex-table'),
          meta: { title: 'complex-table', icon: 'table' }
        },
        {
          path: 'tree',
          name: 'Tree',
          parentId: 'example1',
          id:'tree',
          component: () => import('@/views/tree/index'),
          meta: { title: '树', icon: 'tree' }
        },
        {
          path: '/form',
          component: 'Layout',
          parentId: '',
          id:'form1',
        },
        {
          path: 'index',
          name: 'Form',
          parentId: 'form1',
          id:'form',
          component: () => import('@/views/form/index'),
          meta: { title: '上传', icon: 'form' }
        },
         {
          path: '/nested',
          component: 'Layout',
          redirect: '/nested/menu1',
          name: 'Nested',
          parentId: '',
          id:'nested1',
          meta: {
            title: '多层嵌套',
            icon: 'nested'
          },
        },
        {
          path: 'menu1',
          component: 'nested/menu1/index', // Parent router-view
          name: 'Menu1',
          parentId:'nested1',
          id:'meun1',
          meta: { title: '菜单1' },
        },
        {
          path: 'menu1-1',
          component: () => import('@/views/nested/menu1/menu1-1/index'),
          name: 'Menu1-1',
          parentId:'meun1',
          id:'meun1-1',
          meta: { title: '菜单1-1' }
        },
        {
          path: 'menu1-2',
          component: () => import('@/views/nested/menu1/menu1-2/index'),
          name: 'Menu1-2',
          parentId:'meun1',
          id:'meun1-2',
          meta: { title: '菜单1-2' },
        },
        // {
        //   path: 'menu1-2-1',
        //   component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1/index'),
        //   name: 'Menu1-2-1',
        //   parentId:'meun1-2',
        //   id:'meun1-2-1',
        //   meta: { title: '菜单1-2-1' }
        // },
        {
          path: 'menu2',
          name: 'Menu2',
          parentId:'nested1',
          id:'meun2',
          component: () => import('@/views/nested/menu2/index'),
          meta: { title: '菜单2' }
        },
        {
            path: '/permission',
            component: 'Layout', 
            name: 'permission',
            parentId:'',
            id:'permission',
            redirect: 'permission/permission1',
            meta: { title: '权限', icon: 'link', role: ['admin']},
          }, 
          {
            path: 'permission1',
            name: 'permission1',
            parentId:'permission',
            id:'permission1',
            component: () => import('@/views/permission/permission1/index'),
            sub_view:'permission/permission1/index',
            meta: { title: '用户权限1', role: ['admin']}
        },
        {
            path: 'permission2',
            name: 'permission2',
            parentId:'permission',
            id:'permission2',
            component: () => import('@/views/permission/permission2/index'),
            sub_view:'permission/permission2/index',
            meta: { title: '用户权限2', role: ['admin']}
        },
        {
            path: '/commonUser',
            component: () => import('@/views/commonUser/index.vue'),
            sub_view:'commonUser/index.vue',
            name: '权限测试c',
            parentId:'',
            id:'commonUser',
            redirect: '/commonUser/index',
            meta: { role: ['commonUser'] } 
        }
            
        ] ,
        'editor-token': {
            roles: ['editor'],
            introduction: 'I am an editor',
            avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            name: 'Normal Editor',
            routers:[]
        }
  }}

//异步挂载的路由
//动态需要根据权限加载的路由表 
const asyncRouterMap = [
  {
    path: '/permission',
    component: 'Layout', 
    redirect: '/permission/permission1',
    name: 'permission',
    meta: { title: 'permission', icon: 'link', role: ['admin']},
    children: [
      {
        path: 'permission1',
        name: 'permission1',
        component: () => import('@/views/permission/permission1/index'),
        meta: { title: 'permission1', role: ['admin']}
      },
      {
        path: 'permission2',
        name: 'permission2',
        component: () => import('@/views/permission/permission2/index'),
        meta: { title: 'permission2', role: ['admin']}
      }
    ]
    }, {
    path: '/commonUser',
    component: () => import('@/views/commonUser/index.vue'),
    name: '权限测试c',
    meta: { role: ['commonUser'] } 
  },{
     path: '*', redirect: '/404', hidden: true 
    }
  ]


export default [
  // user login
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.'
        }
      }

      return {
        code: 20000,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
